import router from '@/router'
function getPath(path) {
  return () => import('_views/' + path)
}
export default {
  namespaced: true,
  state: {
    flexNav: sessionStorage.getItem('asidNav') ? JSON.parse(sessionStorage.getItem('asidNav')) : [],
    flexRouter: []
  },
  mutations: {
    // 获取
    INIT_NAV(state, data) {
      state.flexNav = data
    },
    // 添加动态路由
    INIT_ROUTER(state, data) {
      data.forEach(item => {
        item.component = getPath(item.component)
        router.addRoute('admin', item)
      })
      // 无法使用这个动态添加，只能在router内提前定义重定向
      // router.addRoute('admin', {
      //   path: '/',
      //   redirect: '/dashBoard'
      // })
      router.addRoute({
        path: '*',
        name: 'notFound',
        component: () => import('_views/NotFound')
      })
      console.log(data)
    }
  }
}
